package com.pc.web.boardEvent;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pc.web.member.MemberService;

@Controller
public class BoardEventController {
	@Autowired BoardEventDAO dao;
	@Autowired BoardEventService service;
	@Autowired MemberService Mservice;
		
	//글쓰기 폼 페이지
	@RequestMapping(value = "/boardEvent/writeForm", method = RequestMethod.GET)
	public String writeFormpage(){
		return "/boardEvent/boardEvent_writeForm";
	}
	//글쓰기 페이지
	@RequestMapping(value = "/boardEvent/write", method = RequestMethod.POST)
	public String writePage(HttpServletRequest request, PageEventBeans Pbeans, BoardEventBeans beans,Model model){
		//클라이언트 ip추적
		String boardEvent_ip=request.getRemoteAddr();
		beans.setBoardEvent_ip(boardEvent_ip);
		dao.insert(beans);
		service.listpage(beans, Pbeans, model);
		return "/boardEvent/boardEvent_list";
	}
	//글 리스트 페이지
	@RequestMapping(value = "/boardEvent/list", method = {RequestMethod.GET, RequestMethod.POST})
	public String listPage(BoardEventBeans beans, PageEventBeans Pbeans, Model model){
		service.listpage(beans, Pbeans, model);
		return "/boardEvent/boardEvent_list";
	}
	
	//글 상세보기 페이지
	@RequestMapping(value = "/boardEvent/detail", method = {RequestMethod.GET, RequestMethod.POST})
	public String detailViewPage(String boardEvent_no, BoardEventBeans beans, HttpSession session, Model model){
		dao.countUpdate(boardEvent_no);
		service.view(boardEvent_no, beans, model);
		return "/boardEvent/boardEvent_detailView";
	}
	
	//글 수정상세 페이지
	@RequestMapping(value = "/boardEvent/modifyView", method = {RequestMethod.GET, RequestMethod.POST})
	public String modifyViewPage(String boardEvent_no, BoardEventBeans beans, Model model){
		beans=dao.modifyView(boardEvent_no);		
		model.addAttribute("beans", beans);
		return "/boardEvent/boardEvent_modifyView";
	}
	
	//글 수정 페이지
	@RequestMapping(value = "/boardEvent/modify", method = RequestMethod.POST)
	public String modifyPage(String boardEvent_no, BoardEventBeans beans, PageEventBeans Pbeans, Model model){
		dao.update(beans);
		model.addAttribute("beans", beans);
		service.listpage(beans, Pbeans, model);
		return "/boardEvent/boardEvent_list";
	}

	//글 삭제 페이지
	@RequestMapping(value = "/boardEvent/delete", method = RequestMethod.GET)
	public String deletePage(String boardEvent_no, BoardEventBeans beans, PageEventBeans Pbeans, Model model){
		dao.delete(boardEvent_no);
		service.listpage(beans, Pbeans, model);
		return "/boardEvent/boardEvent_list";
	}

	//댓글 삭제 페이지
	@RequestMapping(value = "/boardEvent/commentDelete", method = RequestMethod.POST)
	public String commentDelete(String boardEvent_no, String boardEvent_number, BoardEventBeans beans, PageEventBeans Pbeans, Model model){
		dao.commentDelete(boardEvent_number);
		dao.commentList(boardEvent_no);
		service.view(boardEvent_no, beans, model);
		return "/boardEvent/boardEvent_detailView";
	}

	//댓글 입력 및 리스트
	@RequestMapping(value = "/boardEvent/commentInsert", method = RequestMethod.POST)
	public String commentInsert(String boardEvent_no, BoardEventBeans beans, Model model){
		dao.commentInsert(beans);
		service.view(boardEvent_no, beans, model);
		return "/boardEvent/boardEvent_detailView";
	}
}